//
//  InfoSharingViewController.m
//  Utils
//
//  Created by enghou on 2018/6/4.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "InfoSharingViewController.h"
#import "NetWorkerManager.h"
#import "InfoListViewController.h"
@interface InfoSharingViewController ()

@property(nonatomic,strong)NSMutableArray *source;

@end

@implementation InfoSharingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.source = [NSMutableArray array];
    self.title = @"共享资料";
    [self beginLoading];
    [[NetWorkerManager sharedInstance]postWithPath:@"/mobile/comprehensiveGovernance/sharedDocuments/getSharedDocumentsTypes.action" parameter:nil completeBlock:^(NSDictionary *source) {
        [self endLoading];
        BaseModel *model = [[BaseModel alloc]initWithSourceDict:source];
        if (model.success) {
            NSArray *data = [source objectForKey:@"data"];
            self.source = [data mutableCopy];
            [self.tableView reloadData];
        }else{
            [self alertSome:model.msg];
        }
    } failBlock:^(NSInteger code) {
        [self endLoading];
        [self alertSome:kNetWorkFail];
    }];
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.source.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    NSDictionary *element = [self.source objectAtIndex:indexPath.section];
    cell.textLabel.text = element[@"name"];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 10;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]init];
    view.backgroundColor = [UIColor defaultBackgroundColor];
    return view;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *element = self.source[indexPath.section];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    InfoListViewController *infoList = [[InfoListViewController alloc]init];
    infoList.directoryId = element[@"id"];
    infoList.title = element[@"name"];
    [self push:infoList];
}

@end
